package org.easydarwin.network;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import android.content.Context;

import org.easydarwin.easyrtc.TheApp;

public class RequestManager {

	public static final int OUT_TIME = 10000;
	public static final int TIMES_OF_RETRY = 0;

	public static RequestQueue mRequestQueue;

	public static void init(Context context){
		mRequestQueue = Volley.newRequestQueue(context);
	}
	
	private RequestManager() {
	}

	public static void addRequest(Context tag, Request<?> request) {
		if (tag != null) {
			request.setTag(tag);
		}
		// 给每个请求重设超时、重试次数
		request.setRetryPolicy(new DefaultRetryPolicy(OUT_TIME, TIMES_OF_RETRY, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

		mRequestQueue.add(request);
	}

	public static void cancelAll(Object tag) {
		mRequestQueue.cancelAll(tag);
	}
}
